package com.camera.yl.v.models

import android.view.View
import androidx.lifecycle.MutableLiveData
import com.camera.base.Log.YLogImpl
import com.camera.base.bean.CameraCfg
import com.camera.base.inerface.ICPInterface
import com.camera.base.util.StorageUtil
import com.camera.base.v.models.BaseViewModel
import com.camera.base.v.models.SystemNavBarViewModel
import com.camera.yl.views.CameraManager
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class CameraViewModel @Inject constructor(icpInterface: ICPInterface?,var systemNavBarViewModel: SystemNavBarViewModel?) :
    BaseViewModel() {
    val TAG = CameraViewModel::class.java.simpleName
        var cameraList:List<CameraCfg>? = CameraManager.getCameras()
        val resolution: MutableLiveData<String> by lazy {
                MutableLiveData<String>()
        }
        val capture: MutableLiveData<String> by lazy {
            MutableLiveData<String>()
        }
        val total: MutableLiveData<String> by lazy {
            MutableLiveData<String>()
        }
        val flashSwitch: MutableLiveData<Boolean> by lazy {
            MutableLiveData<Boolean>()
        }
        val switchCameraVisibility: MutableLiveData<Int> by lazy {
            MutableLiveData<Int>()
        }
        val nightVisibility: MutableLiveData<Int> by lazy {
            MutableLiveData<Int>()
        }
        val cameraRecordVisibility: MutableLiveData<Boolean> by lazy {
            MutableLiveData<Boolean>()
        }
        val cameraCaptureVisibility: MutableLiveData<Boolean> by lazy {
            MutableLiveData<Boolean>()
        }
        var mIcpInterface: ICPInterface?
        init {
            cameraRecordVisibility.value = true
            cameraCaptureVisibility.value = true
            mIcpInterface = icpInterface
            icpInterface?.let {
                resolution.value = (icpInterface.recordSize?.width.toString() + "x" + icpInterface.recordSize?.height.toString()).let {
                    "R:$it"
                }
                capture.value = (icpInterface.captureSizeArray[icpInterface.captureChoose][0].toString() + "x" + icpInterface.captureSizeArray[icpInterface.captureChoose][1].toString()).let {
                    "C:$it"
                }
                total.value = StorageUtil.getAvailableStorageInMB().let {
                    if (StorageUtil.isExternalSDCard) "外:"+ "$it MB" else "内:"+ "$it MB"
                }
                switchCameraVisibility.value = if(icpInterface.cameras.size > 1) View.VISIBLE else View.GONE
                YLogImpl.d(TAG,"当前夜视模式 "+icpInterface.getCameraSuperNight())
                nightVisibility.value = if(icpInterface.getCameraSuperNight() > 0) View.VISIBLE else View.GONE
                flashSwitch.value = if(CameraManager.flashCurrent == 0)  false else true
            }

        }
    override fun onCleared() {
        super.onCleared()
    }
    fun flash(){
        CameraManager.flash()
        flashSwitch.value = if(CameraManager.flashCurrent == 0)  false else true
    }
    fun switchCamera(){
        nightVisibility.value = if(mIcpInterface!!.getCameraSuperNight() > 0) View.VISIBLE else View.GONE
    }
}